package com.baosight.sczx.zm.cm.service;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.baosight.iplat4j.core.ei.EiConstant;
import com.baosight.iplat4j.core.ei.EiInfo;
import com.baosight.iplat4j.ep.ServiceEPBase;
import com.baosight.sczx.common.zm.cInterface.cs.InitialData;
import com.baosight.sczx.zm.cm.domain.ZMCMMaterialBase;


/**
 * 库存信息-库存信息
 * <p>Title: ServiceZMCM91.java</p>
 * <p>Description: </p>
 * <p>Copyright: Baosight Software LTD.co Copyright (c) 2002</p>
 * <p>Company: Baosight Software</p>
 * @author 杨鸣
 * @version 1.0
 * <pre>Histroy:
 *          2011-6-22 上午10:51:30  杨鸣  Create
 *</pre>
 */

public class ServiceZMCM90 extends ServiceEPBase {

	/**初始数据
	 * <p>Function: initLoad</p>
	 * <p>Description: </p>
	 * <p>return value: ServiceZMCM02</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2011-5-30 上午09:49:43  杨鸣
	 * </p>
	 *
	*/
	@Override
	public EiInfo initLoad(EiInfo inInfo) {
		inInfo.addBlock(EiConstant.resultBlock).set("showCount", "true");//如果不加这个，翻页的统计和显示是错误的
		EiInfo outInfo = this.query(inInfo);
		outInfo.addBlock(InitialData.getInstance().getEiBlockByNo("cmes.cs.units",true));
		return outInfo;
	}

	/**列表查询
	 * <p>Function: query</p>
	 * <p>Description: </p>
	 * <p>return value: ServiceZMCM02</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2011-5-30 上午09:49:43  杨鸣
	 * </p>
	 *
	*/
	@Override
	public EiInfo query(EiInfo inInfo) 
	{
		EiInfo outInfo = super.query(inInfo, "ZMCMMaterialBase.query",new ZMCMMaterialBase());
		Map inMap = new HashMap();
		
		if(inInfo.getBlock(EiConstant.queryBlock) != null)
		{
			String fdMaterialCode = inInfo.getBlock(EiConstant.queryBlock).getCellStr(0, "fdMaterialCode");
			String fdMaterialName = inInfo.getBlock(EiConstant.queryBlock).getCellStr(0, "fdMaterialName");
			String fdQuality = inInfo.getBlock(EiConstant.queryBlock).getCellStr(0, "fdQuality");
			String fdSpecModel = inInfo.getBlock(EiConstant.queryBlock).getCellStr(0, "fdSpecModel");
			String fdNumber = inInfo.getBlock(EiConstant.queryBlock).getCellStr(0, "fdNumber");
			String fdMetric = inInfo.getBlock(EiConstant.queryBlock).getCellStr(0, "fdMetric");
			
			if(fdMaterialCode != null || !"".equals(fdMaterialCode))
			{
				inMap.put("fdMaterialCode", fdMaterialCode);
			}
			if(fdMaterialName != null || !"".equals(fdMaterialName))
			{
				inMap.put("fdMaterialName", fdMaterialName);
			}
			if(fdQuality != null || !"".equals(fdQuality))
			{
				inMap.put("fdQuality", fdQuality);
			}
			if(fdSpecModel != null || !"".equals(fdSpecModel))
			{
				inMap.put("fdSpecModel", fdSpecModel);
			}
			if(fdNumber != null || !"".equals(fdNumber))
			{
				inMap.put("fdNumber", fdNumber);
			}
			if(fdMetric != null || !"".equals(fdMetric))
			{
				inMap.put("fdMetric", fdMetric);
			}
		}
		List list = dao.query("ZMCMMaterialBase.queryBaseSum", inMap);
		outInfo.set("baseSum", ((HashMap)list.get(0)).get("baseSum"));
		outInfo.set("querySum", ((HashMap)list.get(0)).get("querySum"));
		return outInfo;
	}


	/**
	 * 
	 * <p>Function: update</p>
	 * <p>Description: </p>
	 * <p>return value: ServiceZMCM90</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2011-6-1下午08:06:26 杨鸣
	 * </p>
	 *
	 */
	@Override
	public EiInfo update(EiInfo inInfo) {

			EiInfo outInfo = super.update(inInfo, "ZMCMMaterialBase.updateSafeBaseNum");
			return outInfo;

	}
	

}
